package com.songlanyun.modules.studying.controller.api;


import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.studying.entity.Studying;
import com.songlanyun.modules.studying.model.StudyingVO;
import com.songlanyun.modules.studying.service.StudyingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/studying")
public class ApiStudyingController extends AbstractApiController {


    @Autowired
    private StudyingService studyingService;


    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        params.put("detail_status", 1);//章节状态
        params.put("has_status", 1);//课程状态
        PageUtils page = studyingService.queryPage(params);
        return R.ok().put("page", page);
    }

    @GetMapping("/info/{id}")
    public R list(@PathVariable("id") Long id) {
        StudyingVO vo = studyingService.info(id, getUserId(true));
        return R.ok().put("data", vo);
    }

    /**
     * 最近观看分页列表
     */
    @GetMapping("/studyingLately/page")
    public R studyingLatelyPage(@RequestParam Map<String, Object> params) {
        params.put("user_id", getUserId(true));
        PageUtils page = studyingService.studyingLatelyPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 最近观看
     */
    @GetMapping("/studyingLately/{limit}")
    public R studyingLately(@PathVariable("limit") Integer limit) {
        List<Studying> list = studyingService.studyingLately(getUserId(true), limit);
        return R.ok().put("list", list);
    }
}
